#ifndef _FILTER_H_
#define _FILTER_H_

/****************************************************************************************
本文件代码参考自betaFlight
github网址 https://github.com/betaflight/betaflight
****************************************************************************************/

#include <stdint.h>

/// @brief
typedef struct biquadFilter
{
    float b0, b1, b2, a1, a2;
    float d1, d2;
} biquadFilter_t;

/// @brief 
typedef enum
{
    FILTER_LPF,
    FILTER_NOTCH
} biquadFilterType_e;

/// @brief 低通滤波
typedef struct
{
    float K;
    float LastValue;
} LowPassFilter_t;

/// @brief 滑动滤波
typedef struct
{
    uint32_t Index; // 请初始化为0
    uint32_t BufferSize;
    float *Buffer;
    float Sum; // 请初始化为0
} SlidingFilter_t;

/// @brief 双二阶滤波初始化
/// @param filter 
/// @param samplingFreq 
/// @param filterFreq 
void biquad_filter_init_lpf(biquadFilter_t *filter, uint16_t samplingFreq, uint16_t filterFreq);

/// @brief 根据输入滤波获得输出
/// @param filter 
/// @param input 
/// @return 
float biquad_filter(biquadFilter_t *filter, float input);

/// @brief 一阶低通滤波
/// @param filter
/// @param in
/// @return
float LowPassFilter(LowPassFilter_t *filter, float in);

/// @brief 滑动滤波
/// @param filter
/// @param in
/// @return
float SlidingFilter(SlidingFilter_t *filter, float in);

#endif /*_FILTER_H_*/
